package org.zfes.snowier.cloud.zbss.widget.act.route.service.tea;

import java.util.Map;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.auth.shiro.util.SecurityUtil;
import org.zfes.snowier.cloud.zbss.widget.act.dto.ActSubjectCreateDto;
import org.zfes.snowier.cloud.zbss.widget.act.model.ActSubject;
import org.zfes.snowier.cloud.zbss.widget.act.service.IActSubjectService;
@Controller("org.zfes.snowier.cloud.zbss.widget.act.route.service.tea.actSubjectController")
@RequestMapping("/active/service/tea/actSubject")
public class ActSubjectController extends BaseController {
	
	@Autowired
	private IActSubjectService actSubjectService;
	
    @RequestMapping(value="/createActSubject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object createActSubject(ActSubjectCreateDto actSubjectDto){
		actSubjectService.createActSubject(actSubjectDto,SecurityUtil.getUserId().get());
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
    
    @RequestMapping(value="/startActSubject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object  startActSubject(Long subjectId) {
    	actSubjectService.startActSubject(subjectId);
    	return ajaxDoneSuccess("数据操作成功 ");
	 }
	 
    @RequestMapping(value="/endActSubject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public  @ResponseBody Object endActSubject(Long subjectId){
    	actSubjectService.endActSubject(subjectId);
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	 
	 
	 
    @RequestMapping(value="/loadActSubjectDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadActSubjectDataSet(@RequestParam Map<String,Object> params){
    	
    	params.put("creatorUserId", SecurityUtil.getUserId().orElse(null));
    	params.put("status", Byte.valueOf("1"));
    	
	    DataSet dataSet=  actSubjectService.loadActSubjectDataSet(params);
	    
	    return ajaxQuery("dataSet", dataSet);
    }
	
	
    @RequestMapping(value="/loadActSubject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object loadActSubject(Long id){
		Optional<ActSubject> ops = actSubjectService.loadActSubjectById(id);
		return ajaxQuery("actSubject",ops);
    }
	

    @RequestMapping(value="/updateActSubject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object updateActSubject(Long subjectId,ActSubjectCreateDto actSubjectDto){
		actSubjectService.updateActSubject(subjectId,actSubjectDto);
		return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/deleteActSubject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public @ResponseBody  Object deleteActSubject(Long id){
		actSubjectService.setActSubjectStatus(id, Byte.valueOf("-1"));
		return ajaxDoneSuccess("数据操作成功 ");
    }

}